﻿using System.Threading;
using Catel.IoC;
using Catel.Messaging;

namespace Shell.Library.ViewModels
{
    /// <summary>
    /// Base class for all view models in Orchestra. Additional functionality might be introduced in the future.
    /// </summary>
    public class ViewModel : Catel.MVVM.ViewModelBase
    {
        public IMessageMediator MessageMediator { get; private set; }
        protected SynchronizationContext ThreadUiContext { get; private set; }

        public ViewModel()
        {
            ThreadUiContext = SynchronizationContext.Current;
            MessageMediator = ServiceLocator.ResolveType<IMessageMediator>();
            MessageMediator.Register<string>(this, m => ThreadUiContext.Send(o => OnMessageReceived(o.ToString()), m));
        }

        protected virtual void OnMessageReceived(string message) { }
    }
}